www.gusucode.com > Simulink for Circuit Analysis 工具箱matlab源码程序 > Simulink for Circuit Analysis/Compute_TF.m
function [H,Fvec] = Compute_TF(model ) % Compute DUT Frequency response using Simulink Conrol Design. Fstart = str2num(get_param([model,'/Fstart'],'Value')); Fstop = str2num(get_param([model,'/Fstop'],'Value')); NumPt = str2num(get_param([model,'/Number_of_Points'],'Value')); io = getlinio(model); op = operpoint(model); % The Initial Conditions % should all be zero for passive linear model. % Linearize the model, but it should already be linear. sys = linearize(model,io,op); dF = (Fstop-Fstart)/(NumPt-1); Fvec = Fstart:dF:Fstop; focus = {Fvec(2)*2*pi,Fvec(end)*2*pi}; scaledsys = prescale(sys,focus); % see docs H = freqresp(scaledsys,2*pi*Fvec); % ditto % Plot Results close Size_Hw = size(H); if Size_Hw(1) ==1 % Single Input Single Output ax_mag = subplot(2,1,1); plot(ax_mag,Fvec*1e-6,20*log10(abs(squeeze(H(1,1,:))))) ylabel('dB'); xlabel('MHz'); ax_phase = subplot(2,1,2); plot(ax_phase,Fvec*1e-6,(180/pi)*unwrap(angle(squeeze(H(1,1,:))))) ylabel('Degrees'); xlabel('MHz'); set(gcf,'Name',[model,'.mdl']); elseif Size_Hw(1)==2 % Single Input, Two Outputs for Comparision Purposes. ax_mag = subplot(2,1,1); plot(ax_mag,Fvec*1e-6,20*log10(abs(squeeze(H(1,1,:))))) hold on plot(ax_mag,Fvec*1e-6,20*log10(abs(squeeze(H(2,1,:)))),'+') legend('Behavioral','Circuit') ylabel('dB'); xlabel('MHz'); ax_phase = subplot(2,1,2); plot(ax_phase,Fvec*1e-6,(180/pi)*unwrap(angle(squeeze(H(1,1,:))))) hold on plot(ax_phase,Fvec*1e-6,(180/pi)*unwrap(angle(squeeze(H(2,1,:)))),'+') ylabel('Degrees'); xlabel('MHz'); hold off legend('Behavioral','Circuit') set(gcf,'Name',[model,'.mdl']); else disp('Edit the Frequency Response Block OpenFcn Callback to support more IO'); end; end